<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<jsp:include page="/WEB-INF/jspf/header.jsp">
    <jsp:param name="title" value="Transfer Money" />
</jsp:include>

<f:view>
    <h:form id="form" >
        <h:outputText rendered="#{bankTransaction.initAccountDetails}" />

        <%@include file="/WEB-INF/jspf/menu_customer.jspf" %>

        <h:inputHidden binding="#{bankTransaction.inputHidden}" value="#{bankTransaction.accountId}"  />

        <h1><h:outputText value="Transfer Money" /></h1>
        <h3><h:outputText value="Account Id: #{bankTransaction.accountId}" /></h3>
        <h3><h:outputText value="Account balance: #{bankTransaction.balance} #{bankTransaction.accountCurrency}" /></h3>

        <h:panelGrid columns="3">
            <h:outputText value="Account number"/>
            <h:inputText  id="toId" value="#{bankTransaction.to}" title="To"  required="true" converterMessage="Account number is not valid." validatorMessage="Account does not exist."  requiredMessage="Fill valid account number.">
                <f:validator validatorId="checkAccount" />
            </h:inputText>
            <h:message  errorClass="error"  for="toId" id="msg" />


            <h:outputText value="Amount"/>
            <h:inputText id="amount" value="#{bankTransaction.amount}"  title="Ammount" required="true" validatorMessage="Amount value is not correct." requiredMessage="Fill valid amount value." >
                <f:validateDoubleRange minimum="0.01"  />
            </h:inputText>
            <h:message infoClass="info" errorClass="error" for="amount"/>

            <h:outputText value="Currency:"/>
            <h:selectOneMenu validatorMessage="Currency Error" requiredMessage="Currency Error." id="currency" required="true" value="#{bankTransaction.currency}">
                <f:converter converterId="CurrencyConverter" />
                <f:selectItems value="#{account.currencyChoices}" />
            </h:selectOneMenu>
            <h:message infoClass="info" errorClass="error" for="currency"/>

        </h:panelGrid>
        <h:commandButton action="#{bankTransaction.create}" value="Transfer"label="Transfer" />


        <h:outputLink value="viewTransactions.jsp" >
            <f:param name="accountId" value="#{bankTransaction.inputHidden.value}"/>
            <h:outputText value="View Transactions"/>
        </h:outputLink>
    </h:form>

    </body>
    </html>
</f:view>
